package com.click369.crm.controller;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

@Component
public class GlobaExceptionResolver implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object obj,
			Exception ex) {
		// handler==>有requestMapping()注解的方法
		if(ex != null){
			/**
			 * 默认的视图解析器是jstl
			 * 返回json
			 */
			ModelAndView mv = new ModelAndView();
			//设置json的视图解析器
			mv.setView(new MappingJackson2JsonView());
			mv.addObject(new String("权限不足，请联系管理员！"));
			return mv;
		}
		return null;
	}

}
